home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
tvmacro.exe
/
MACROS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-01-31
|
20KB
|
701 lines
unit Macros;
(***************************************************************************)
(* Turbo Vision Macros *)
(* $25 Shareware, Version 1.0 *)
(* *)
(* (c) Copyright 1992 Cybersoft & Lawrence V. Koepke *)
(* All Rights Reserved *)
(* *)
(* Cybersoft *)
(* 1921 Minto Dr., San Jose, CA 95132 *)
(* (408) 272-2927 *)
(***************************************************************************)
{$X+}
{.$DEFINE TESTING}
{
Turbo Vision Macros is a complete Event Macro Handler, and is released as
Shareware. If you find it useful, please support my efforts. I am an
independant developer. I have no job... I support the wife and kids with my
wits and perseverance to succeed. If enough people support my efforts with
TV Macros, I may even release future versions that support advanced features
(i.e. Loops, If-Then, etc.)! I encourage you to pass this code on to your
friends and colleagues, for, if nothing else, I'm sure that it will make some
people's jobs easier; but, please, do not pass on modified code... let's
have some version control here, send me your modifications.
This unit Replaces TApp.GetEvent with a method having the following features:
- Records events as macros
- Plays back events in macros
- Both Mouse and Keyboard supported
- Macros can record the playback of other macros
- Macros are selected from a pick-list for playback
- Macros are given a name up to 50 characters long
- Halt playback with Escape and confirmation (requires MsgBox)
- Adds app. 16K to the application (with integrated debugger information)
- All non-current macros are kept on disk, macros are only loaded when run
- Does NOT replace BIOS keyboard interrupt 16 or 9
- Macros are stored in two files : MACROS.NDX and MACROS.MAC.
Macros requires units Lists and Picks (also from Cybersoft) to compile.
}
interface
uses App, Drivers, Picks, Lists, StdDlg, Objects, Dialogs;
type
(*-------- The basic App type to include macros ------------------*)
PMacApp = ^TMacApp;
TMacApp = object (TApplication)
constructor Init;
destructor Done; virtual;
procedure GetEvent (var Event : TEvent); virtual;
end;
(*-------- The Macro Dialog (replaces event handler) ----------*)
PMacDialog = ^TMacDialog;
TMacDialog = object (TDialog)
procedure HandleEvent (var Event : TEvent); virtual;
end;
(*-------- Macro file record ----------------------------------*)
AMacroRecord = TEvent; {used to define file record}
(*-------- Macro Index file record ----------------------------*)
AMacroIndex = Record
Name : String [50];
Start,
Length : Integer;
end;
(*-------- The Macro ------------------------------------------*)
{ Each macro is a collection of Events of type TEvent. }
PMacro = ^TMacro;
TMacro = object (TQueue)
end;
(*------- A stack of macros. ----------------------------------*)
{ Used to store interrupted macros (ones that call
other macros. (A Stack of Queues, so to speak.) }
PMacroStack = ^TMacroStack;
TMacroStack = object(TStack)
procedure PushMacro (Macro : PMacro);
end;
(*------- The macro picklist ----------------------------------*)
(* - - - - - - - - -- - - - - - -- - - - - *)
{ Used for Sorted macro list. }
TSortRecord = record
Name : String [50];
RecNUm : integer;
end;
PMacroList = ^TMacroList;
TMacroList = object (TSortedCollection)
function Compare (Key1, Key2 : Pointer): Integer; virtual;
procedure FreeItem (Item : Pointer); virtual;
end;
PMacroListBox = ^TMacroListBox;
TMacroListBox = object (TSortedListBox) {from StdDlg}
procedure HandleEvent (var Event : TEvent); virtual;
function GetText (Item : Integer; MaxLen : Integer) : String; virtual;
end;
(*-------------------------------------------------------------*)
PEvent = ^TEvent;
procedure StartRecording;
procedure StopRecording;
procedure StartPlayback;
procedure StopPlayback;
procedure DeleteMacro; {Can this be disabled during Recording or playback?}
implementation
uses Views, Strings, Crt, MsgBox;
type PSortRecord = ^TSortRecord;
var
MacroFile : file of AMacroRecord; {file of macros}
MacroFileIndex : file of AMacroIndex; {file of indexes to macros}
MacFileName : string; {file name root; no ext.}
RecordMacIndex : AMacroIndex; {1 index record}
MacPickList : PPickList; {picklist of macros}
MacStack : PMacroStack; {collection of macros}
InRecording,
InPlayback : boolean; {states}
PtrEvent : PEvent; {used only in GetEvent}
OurMacro : PMacro; {the current macro}
CheckHalt : boolean; {allows macro interruption}
(* ------------------------- The Macro Files ---------------------------- *)
function OpenMacroFiles (Filename : string): boolean;
var ok : boolean;
begin
ok := false;
{$I-}
Assign (MacroFile, Filename + '.MAC');
Reset (MacroFile);
ok := IOResult = 0;
if not ok then
begin
Rewrite (MacroFile);
ok := IOResult = 0;
if not ok then
MessageBox('Couldn''t open or create macro data file.',
nil, mfOKButton);
end;
if ok then
begin
Assign (MacroFileIndex, Filename + '.NDX');
Reset (MacroFileIndex);
ok := IOResult = 0;
if not ok then
begin
Rewrite (MacroFileIndex);
ok := IOResult = 0;
if not ok then
MessageBox('Couldn''t open or create macro index file.',
nil, mfOKButton);
end;
end;
OpenMacroFiles := ok;
{$I+}
end;
procedure CloseMacrofiles;
begin
Close (MacroFile);
Close (MacroFileIndex);
end;
(* ------------------------ The Macro Dialog Box ------------------------- *)
{This HandleEvent replaces the space with an underscore because StdDlg's
TSortedListBox does not recognize spaces with alphanumeric searches for
the list items. This HandleEvent also converts characters to upper-case,
since TSortedListBox is case-sensitive.}
procedure TMacDialog.HandleEvent (var Event : TEvent);
begin
if Event.What = evKeyDown then
if Event.CharCode = #32 then
Event.CharCode := #95
else
Event.CharCode := UpCase(Event.CharCode);
TDialog.HandleEvent (Event);
end;
FUNCTION MakeDialog : PMacDialog;
var
Dlg : PMacDialog;
R : TRect;
Control, Labl, Histry : PView;
Begin
R.Assign(4,6,76,13);
New(Dlg, Init(R, 'Macro'));
R.Assign(17,2,69,3);
Control := New(PInputLine, Init(R, 50));
Dlg^.Insert(Control);
R.Assign(2,2,17,3);
Labl := New(PLabel, Init(R, 'Macro Name : ', Control));
Dlg^.Insert(Labl);
R.Assign(46,4,54,6);
Control := New(PButton, Init(R, ' OK ', cmOK, bfDefault));
Dlg^.Insert(Control);
R.Assign(57,4,67,6);
Control := New(PButton, Init(R, 'Cancel', cmCancel, bfNormal));
Dlg^.Insert(Control);
Dlg^.SelectNext(False);
MakeDialog := Dlg;
end;
var
DataRec : record
Name : String[50]; {Inputline}
end;
(* ---------------------------- MacroStack ------------------------------- *)
procedure TMacroStack.PushMacro (Macro : PMacro);
var P : PMacro;
begin
new (P);
P := Macro;
Push(P);
end;
(* ---------